<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue知识点总结(二.组件化开发) | 小何blog (记录美好)</title><meta name="keywords" content="系列🏬,Vue,组件化"><meta name="author" content="六根清静"><meta name="copyright" content="六根清静"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="组件化是Vue的精髓，Vue就是由一个一个的组件构成的。那么问题来了，什么叫做组件化，为什么要组件化？">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue知识点总结(二.组件化开发)">
<meta property="og:url" content="https://liugenqingjing2.coding.me/2020/08/20/Vue%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%BA%8C-%E7%BB%84%E4%BB%B6%E5%8C%96%E5%BC%80%E5%8F%91/index.html">
<meta property="og:site_name" content="小何blog (记录美好)">
<meta property="og:description" content="组件化是Vue的精髓，Vue就是由一个一个的组件构成的。那么问题来了，什么叫做组件化，为什么要组件化？">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200820/3IlRh8gQ9aXk.jpeg">
<meta property="article:published_time" content="2020-08-20T11:07:16.000Z">
<meta property="article:modified_time" content="2021-01-10T12:28:10.706Z">
<meta property="article:author" content="六根清静">
<meta property="article:tag" content="系列🏬">
<meta property="article:tag" content="Vue">
<meta property="article:tag" content="组件化">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200820/3IlRh8gQ9aXk.jpeg"><link rel="shortcut icon" href="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/wOu*ZmuVb5A4.png"><link rel="canonical" href="https://liugenqingjing2.coding.me/2020/08/20/Vue%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%BA%8C-%E7%BB%84%E4%BB%B6%E5%8C%96%E5%BC%80%E5%8F%91/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin="crossorigin"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e829919a4d931d733ee74d5d97a51582";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":20,"languages":{"author":"作者: 六根清静","link":"链接: ","source":"来源: 小何blog (记录美好)","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-01-10 20:28:10'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '2'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"><link rel="stylesheet" href="/css/shuo.css"/><link rel="stylesheet" href="/magnetcss/magnet.css"/><link rel="stylesheet" href="/css/calendar.css"/><link rel="stylesheet" href="//at.alicdn.com/t/font_2060620_l0j6b710zk.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/font-awesome-animation.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><link rel="stylesheet" href="/css/change.css"><link rel="stylesheet" href="/news/css/news.css"/><style type="text/css">#toggle-sidebar {bottom: 80px}</style><link rel="stylesheet" href="/magnet/css/catalogMagnet.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/iconfont.min.css"><link rel="stykesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/pool.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/><link rel="stylesheet" href="/zan/zan.css"><link rel="stylesheet" href="/swiper/swiper.min.css"><link rel="stylesheet" href="/swiper/swiperstyle.css"><style>#article-container.post-content h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { -webkit-animation: avatar_turn_around 1s linear infinite; -moz-animation: avatar_turn_around 1s linear infinite; -o-animation: avatar_turn_around 1s linear infinite; -ms-animation: avatar_turn_around 1s linear infinite; animation: avatar_turn_around 1s linear infinite; }</style><meta name="generator" content="Hexo 5.0.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200820/3IlRh8gQ9aXk.jpeg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小何blog (记录美好)</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">Vue知识点总结(二.组件化开发)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-08-20T11:07:16.000Z" title="发表于 2020-08-20 19:07:16">2020-08-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-10T12:28:10.706Z" title="更新于 2021-01-10 20:28:10">2021-01-10</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF%E5%AD%A6%E4%B9%A0/">前端学习</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>16分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Vue组件化"><a href="#Vue组件化" class="headerlink" title="Vue组件化"></a>Vue组件化</h1><blockquote>
<p>纯属随笔记录，具体详细教程，请查阅<a target="_blank" rel="noopener" href="https://vuejs.bootcss.com/guide/">vue.js官网</a></p>
</blockquote>
<h2 id="1-组件化的概念"><a href="#1-组件化的概念" class="headerlink" title="1.组件化的概念:"></a>1.组件化的概念:</h2><p>在Vue中，组件是一个很强大的功能，组件可以扩展HTML元素，封装可重用的代码。比如在页面当中的某一个部分需要在多个场景中使用，那么我们可以将其抽出为一个组件来进行复用。组件可以大大提高了代码的复用率。就比如像是一台电脑中的每一个元件部分(键盘，鼠标，显卡，显示屏，硬盘等等)，它是一个具有独立的逻辑和功能或界面，同时又能根据规定的接口规则进行相互融合，变成一个完整的应用，页面就是有一个个类似这样的部分组成，比如导航、列表、弹窗、下拉菜单等。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200821/0AiQe^JJfD!H.jpg" alt="组件化模型图"></p>
<hr>
<h2 id="2-组件化开发的优点"><a href="#2-组件化开发的优点" class="headerlink" title="2.组件化开发的优点:"></a>2.组件化开发的优点:</h2><ol>
<li>高效: 提高开发效率</li>
<li>分治: 便于协同开发,提升整个项目的可维护性</li>
<li>重用: 方便重复使用</li>
<li>组合: 简化调试步骤,简洁方便</li>
</ol>
<hr>
<h2 id="3-组件注册方式"><a href="#3-组件注册方式" class="headerlink" title="3.组件注册方式:"></a>3.组件注册方式:</h2><h4 id="Vue又分为全局注册和局部注册两种方式来注册组件。全局组件它可以在任何-根-实列中使用的组件，局部组件只能在某一实列中使用的组件。"><a href="#Vue又分为全局注册和局部注册两种方式来注册组件。全局组件它可以在任何-根-实列中使用的组件，局部组件只能在某一实列中使用的组件。" class="headerlink" title="Vue又分为全局注册和局部注册两种方式来注册组件。全局组件它可以在任何(根)实列中使用的组件，局部组件只能在某一实列中使用的组件。"></a>Vue又分为全局注册和局部注册两种方式来注册组件。全局组件它可以在任何(根)实列中使用的组件，局部组件只能在某一实列中使用的组件。</h4><ul>
<li><h3 id="全局注册组件"><a href="#全局注册组件" class="headerlink" title="全局注册组件:"></a>全局注册组件:</h3><ul>
<li><p><strong>语法:</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 使用:</span><br><span class="line">&lt;div id&#x3D;&quot;app&quot;&gt;</span><br><span class="line">    组件名称</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line"># 注册:</span><br><span class="line">Vue.component(组件名称,&#123;</span><br><span class="line">    data: 组件数据,</span><br><span class="line">    template: 组件模板内容</span><br><span class="line">    其他选项...</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>例子</strong>:</p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Document<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;app&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">button-counter</span>&gt;</span><span class="tag">&lt;/<span class="name">button-counter</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    Vue.component(<span class="string">&#x27;button-counter&#x27;</span>,&#123;</span></span><br><span class="line"><span class="javascript">      data: <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="keyword">return</span>&#123;</span></span><br><span class="line">          count: 0</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line"><span class="handlebars"><span class="xml">      template: &#x27;<span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span> = <span class="string">&quot;count++&quot;</span>&gt;</span>点击了</span><span class="template-variable">&#123;&#123;<span class="name">count</span>&#125;&#125;</span><span class="xml">次<span class="tag">&lt;/<span class="name">button</span>&gt;</span>&#x27;</span></span></span><br><span class="line">    &#125;)</span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="javascript">      el: <span class="string">&#x27;#app&#x27;</span>,</span></span><br><span class="line">      data:&#123;</span><br><span class="line">          </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>效果:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200821/!!Z7XSxkn*wJ.png" alt="初始效果"></p>
</li>
</ul>
</li>
</ul>
<p>​                                                                                      <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200821/EME@47rRsN!n.png" alt="点击后的效果"></p>
<p>​                                                             <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200821/LreGqO!^idce.png" alt="组件复用,用了三次的效果"></p>
<h4 id="注"><a href="#注" class="headerlink" title="注:"></a>注:</h4><p>​                1.组件是可以复用的，而且每个组件的数据相互独立。</p>
<p>​                2.每一个组件的选项都包括一个Vue实例的完整内容，比如methods，computed，data等还有生命周期                函数。</p>
<p>​                3.使用自定义组件之前必须注册。</p>
<p>​                4.<code>data</code>必须是一个函数，与普通Vue对象实例比较。</p>
<p>​                5. 组件模板内容必须是单个根元素。</p>
<p>​                6.组件模板内容可以是模板字符串。</p>
<p>​                7.全局组件使用范围：可以在页面中任何位置使用</p>
<hr>
<ul>
<li><h3 id="局部组件注册"><a href="#局部组件注册" class="headerlink" title="局部组件注册:"></a>局部组件注册:</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 使用:</span><br><span class="line">&lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;hello-world&gt;&lt;/hello-world&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line"># 注册:</span><br><span class="line"><span class="keyword">var</span> children = &#123;</span><br><span class="line">    template: <span class="string">&#x27;&lt;h1&gt;Hello World&lt;/h1&gt;&#x27;</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">var</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">    components:&#123;</span><br><span class="line">      <span class="string">&#x27;HelloWorld&#x27;</span>: children</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br></pre></td></tr></table></figure>

<p><strong>或者在项目中一般进行组件化开发时这样:</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> HelloWorld <span class="keyword">from</span> <span class="string">&#x27;./components/HelloWorld&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  components: &#123;</span><br><span class="line">    HelloWorld</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>效果:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200822/NwxnxPSY^^sL.png" alt="效果图"></p>
</li>
</ul>
<h3 id="注-1"><a href="#注-1" class="headerlink" title="注:"></a>注:</h3><ol>
<li>局部组件使用范围：只能在定义它的el中使用，不能再其他位置使用，否则就无法生效</li>
<li>属性名是<code>components</code>，千万别忘了加s与注册全局组件时的<code>component</code>区分开</li>
<li><code>data</code>必须是一个函数，与普通Vue对象实例比较。与全局组件一样</li>
<li>注意用es5和es6语法写，this的指向问题，在非根组件中<code>this</code>指向的都是Vue实例，而在根组件中es6语法指向的是<code>window</code></li>
</ol>
</li>
</ul>
<hr>
<ul>
<li><h3 id="组件命名方式"><a href="#组件命名方式" class="headerlink" title="组件命名方式:"></a>组件命名方式:</h3></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 短横线方式</span><br><span class="line">Vue.component(<span class="string">&#x27;my-component&#x27;</span>,&#123;...&#125;)</span><br><span class="line"> </span><br><span class="line"># 驼峰方式</span><br><span class="line">Vue.component(<span class="string">&#x27;MyComponent&#x27;</span>,&#123;...&#125;)</span><br></pre></td></tr></table></figure>

<ul>
<li>注: 如果使用驼峰式命名组件，那么真使用组件的时候，只能在字符串模板中用驼峰的方式使用组件，但是在普通的标签模板(HTML中的挂载点)中，必须使用短横线的方式使用组件。如何使用看个人喜好</li>
</ul>
<hr>
<ul>
<li><h3 id="组件间的数据交互"><a href="#组件间的数据交互" class="headerlink" title="组件间的数据交互:"></a>组件间的数据交互:</h3><p><strong>图例:</strong></p>
<p>​                                     <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/zhdPYdrzoA0M.png" alt="组件间的数据交互视图:"></p>
<ol>
<li><h4 id="父组件向子组件传值"><a href="#父组件向子组件传值" class="headerlink" title="父组件向子组件传值:"></a>父组件向子组件传值:</h4><figure class="highlight"><table><tr><td class="code"><pre><span class="line"># 组件内部通过props接收传递过来的值</span><br><span class="line"></span><br><span class="line">Vue.component(<span class="string">&#x27;childItem&#x27;</span>,&#123;</span><br><span class="line">      props:[<span class="string">&#x27;title&#x27;</span>],</span><br><span class="line">      template: <span class="string">&#x27;&lt;h2&gt;&#123;&#123;title&#125;&#125;&lt;/h2&gt;&#x27;</span></span><br><span class="line">    &#125;)</span><br><span class="line"></span><br><span class="line"># 父组件通过属性将值传递给子组件</span><br><span class="line"></span><br><span class="line">&lt;child-item :title = &quot;title&quot;&gt;&lt;/child-item&gt;    #动态绑定</span><br><span class="line">&lt;child-item title = &quot;静态传递父组件到子组件&quot;&gt;&lt;/child-item&gt;   #静态传值</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>例子:</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">  &lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;child-item :title = <span class="string">&quot;title&quot;</span>&gt;&lt;/child-item&gt;</span><br><span class="line">    &lt;child-item title = <span class="string">&quot;静态传递父组件到子组件&quot;</span>&gt;&lt;/child-item&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">  &lt;script src=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">  &lt;script&gt;</span><br><span class="line">    Vue.component(<span class="string">&#x27;childItem&#x27;</span>,&#123;</span><br><span class="line">      data: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">return</span>&#123;</span><br><span class="line">          message:<span class="string">&#x27;子组件内容&#x27;</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      props:[<span class="string">&#x27;title&#x27;</span>],</span><br><span class="line">      template: <span class="string">&#x27;&lt;h2&gt;&#123;&#123;message+&quot;---&quot;+title&#125;&#125;&lt;/h2&gt;&#x27;</span></span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">var</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">      el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">      data:&#123;</span><br><span class="line">        title:<span class="string">&#x27;动态传递父组件到子组件&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>效果</strong>:</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/NC!WmwLBzF!0.png" alt="例子效果图"></p>
</li>
<li><h4 id="注-2"><a href="#注-2" class="headerlink" title="注:"></a>注:</h4><ol>
<li><code>props</code>属性命名规则:<ul>
<li>在<code>props</code>中共使用驼峰形式，模板中需要使用短横线的形式</li>
<li>字符串形式的模板没有这个限制</li>
<li>即在HTML中不区分大小写，需要用短横线形式</li>
</ul>
</li>
<li><code>props</code>属性值类型:<ul>
<li>字符串 String</li>
<li>数值 Number  （绑定时用动态绑定才能传对应的类型，否则默认为字符串类型）</li>
<li>布尔值 Boolean  （绑定时用动态绑定才能传对应的类型，否则默认为字符串类型）</li>
<li>数组 Array</li>
<li>对象 Object</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
<li><p><code>props</code>传递原则是: 单向数据流</p>
</li>
</ol>
</li>
</ul>
<hr>
<ol start="2">
<li><h4 id="子组件向父组件传值"><a href="#子组件向父组件传值" class="headerlink" title="子组件向父组件传值"></a>子组件向父组件传值</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 子组件通过$emit(&quot;事件名称&quot;)自定义事件向父组件传递信息</span><br><span class="line"></span><br><span class="line">&lt;button @click = <span class="string">&#x27;$emit(&quot;add-text&quot;,&#123;可传的参数&#125;)&#x27;</span>&gt;扩大字体&lt;/button&gt;</span><br><span class="line"></span><br><span class="line"># 父组件监听子组件的事件</span><br><span class="line"></span><br><span class="line">&lt;main-item @add-text = <span class="string">&quot;add(&#123;$event有参数的话用这个接收参数&#125;)&quot;</span>&gt;&lt;/main-item&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>例子:</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">  &lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">      &lt;p :style = <span class="string">&quot;&#123;fontSize: fontSize + &#x27;px&#x27;&#125;&quot;</span>&gt;&#123;&#123;message&#125;&#125;&lt;/p&gt;</span><br><span class="line">      &lt;child-item @add-font = <span class="string">&quot;add($event)&quot;</span>&gt;&lt;/child-item&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">  &lt;script src=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">  &lt;script&gt;</span><br><span class="line">    Vue.component(<span class="string">&#x27;childItem&#x27;</span>,&#123;</span><br><span class="line">      data: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">return</span>&#123;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      template: <span class="string">`&lt;button @click = &quot;$emit(&#x27;add-font&#x27;,5)&quot;&gt;子组件按钮---文字增大&lt;/button&gt;`</span></span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">var</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">      el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">      data:&#123;</span><br><span class="line">        fontSize: <span class="number">16</span>,</span><br><span class="line">        message:<span class="string">&#x27;父组件内容&#x27;</span></span><br><span class="line">      &#125;,</span><br><span class="line">      methods:&#123;</span><br><span class="line">        add(e)&#123;</span><br><span class="line">          <span class="built_in">this</span>.fontSize += e</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>效果:</strong></li>
</ul>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/1!!CcGi^WzxG.png" alt="默认效果"></p>
<p>​                                                            <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/tk^xPGR81AEA.png" alt="点击两次以后效果"></p>
<ul>
<li><h4 id="注-3"><a href="#注-3" class="headerlink" title="注:"></a>注:</h4><ol>
<li>子组件想把数据传递给父组件的话, 那么可以通过事件触发的方式来传递数据, 父组件使用 v-on / @ 自定义事件进行监听即可。</li>
<li>当传递的事件有参数时，父组件接收事件时用<code>$event</code>，接收参数，如果执行的内容是函数的话可以在HTML中省略<code>$event</code>，在对应的函数接收即可</li>
</ol>
</li>
</ul>
</li>
</ol>
<hr>
<ol start="3">
<li><h4 id="非父组件跟子组件之间的传值（事件总线）："><a href="#非父组件跟子组件之间的传值（事件总线）：" class="headerlink" title="非父组件跟子组件之间的传值（事件总线）："></a>非父组件跟子组件之间的传值（事件总线）：</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/Lek1*eC1^RWk.png" alt="非父组件跟子组件之间的传值示意图"></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 单独的事件总线注册</span><br><span class="line"><span class="keyword">var</span> eventBus = <span class="keyword">new</span> Vue()</span><br><span class="line"></span><br><span class="line"># 监听事件与销毁事件</span><br><span class="line">eventBus.$on(<span class="string">&#x27;事件名称&#x27;</span>,<span class="function">(<span class="params">参数</span>) =&gt;</span>&#123;&#125;)</span><br><span class="line">eventBus.$off(<span class="string">&#x27;事件名称&#x27;</span>)</span><br><span class="line"></span><br><span class="line"># 触发事件</span><br><span class="line">eventBus.$emit(<span class="string">&#x27;事件名称&#x27;</span>,参数)</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ul>
<li><p><strong>例子:</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">  &lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;div&gt;</span><br><span class="line">      &lt;button @click = <span class="string">&quot;over&quot;</span>&gt;销毁功能&lt;/button&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">    &lt;tom-add&gt;&lt;/tom-add&gt;</span><br><span class="line">    &lt;jack-add&gt;&lt;/jack-add&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">  <span class="keyword">var</span> eventBus = <span class="keyword">new</span> Vue()</span><br><span class="line">  Vue.component(<span class="string">&#x27;tom-add&#x27;</span>,&#123;</span><br><span class="line">    data:<span class="function">() =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">return</span>&#123;</span><br><span class="line">        num: <span class="number">0</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">    &lt;div&gt;</span></span><br><span class="line"><span class="string">      &lt;h2&gt;Tom的数量:&#123;&#123;num&#125;&#125;&lt;/h2&gt;</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;button @click = &quot;add&quot;&gt;增加Jack的数量&lt;/button&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">    &lt;/div&gt;</span></span><br><span class="line"><span class="string">    `</span>,</span><br><span class="line">    methods:&#123;</span><br><span class="line">      add()&#123;</span><br><span class="line">        eventBus.$emit(<span class="string">&#x27;add-jack&#x27;</span>,<span class="number">5</span>)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    mounted:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">      eventBus.$on(<span class="string">&#x27;add-tom&#x27;</span>,<span class="function">(<span class="params">e</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.num += e</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  Vue.component(<span class="string">&#x27;jack-add&#x27;</span>,&#123;</span><br><span class="line">    data:<span class="function">() =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">return</span>&#123;</span><br><span class="line">        num: <span class="number">0</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">    &lt;div&gt;</span></span><br><span class="line"><span class="string">      &lt;h2&gt;Jack的数量:&#123;&#123;num&#125;&#125;&lt;/h2&gt;</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;button @click = &quot;add&quot;&gt;增加Tom的数量&lt;/button&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">    &lt;/div&gt;</span></span><br><span class="line"><span class="string">    `</span>,</span><br><span class="line">    methods:&#123;</span><br><span class="line">      add()&#123;</span><br><span class="line">        eventBus.$emit(<span class="string">&#x27;add-tom&#x27;</span>,<span class="number">10</span>)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    mounted:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">      eventBus.$on(<span class="string">&#x27;add-jack&#x27;</span>,<span class="function">(<span class="params">e</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.num += e</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="keyword">var</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">    data:&#123;</span><br><span class="line"></span><br><span class="line">    &#125;,</span><br><span class="line">    methods:&#123;</span><br><span class="line">      over()&#123;</span><br><span class="line">        eventBus.$off(<span class="string">&#x27;add-jack&#x27;</span>)</span><br><span class="line">        eventBus.$off(<span class="string">&#x27;add-tom&#x27;</span>)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>效果:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/hdK1gZ9eOO8A.png" alt="默认效果"></p>
</li>
</ul>
<p>​                                                                           <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/Rqiv67Jiqyik.png" alt="分别点击一次后的效果"></p>
<p>​                                                                            <img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200823/jEQFS1t0Ceer.png" alt="点击销毁事件按钮事件销毁"></p>
<ul>
<li><h4 id="注-4"><a href="#注-4" class="headerlink" title="注:"></a>注:</h4><ol>
<li><p>一般在项目中结合组件化思想很少这样全局写，而是直接在main.js建一个空的Vue实例，用来做中央事件总线：</p>
<p><code>//购物车组件信息交互 Vue.prototype.shopbus = new Vue();</code></p>
</li>
<li><p>在使用完，要销毁的时候，需要及时销毁，最好在组件销毁前清除事件监听</p>
</li>
</ol>
</li>
</ul>
<hr>
<h2 id="4-组件插槽"><a href="#4-组件插槽" class="headerlink" title="4.组件插槽:"></a>4.组件插槽:</h2><ul>
<li><h4 id="组件插槽的概念"><a href="#组件插槽的概念" class="headerlink" title="组件插槽的概念"></a>组件插槽的概念</h4><p>Vue组件化中，当我们在设计一个组件的时候，可能会保留一部分，让使用者自定义的内容，比如：</p>
<ol>
<li>导航栏组件中，右上角的分享按钮，左上角做菜单按钮</li>
<li>弹出框组件中，弹出框的提示内容等</li>
<li>轮播图等等….</li>
</ol>
<p>在这种场景下，保留给使用者的部分，叫做插槽(slot)</p>
</li>
<li><h4 id="作用"><a href="#作用" class="headerlink" title="作用:"></a>作用:</h4><p>父组件向子组件传递内容。</p>
</li>
<li><h4 id="插槽的分类"><a href="#插槽的分类" class="headerlink" title="插槽的分类:"></a>插槽的分类:</h4><ul>
<li><p><strong>匿名插槽:</strong></p>
<ol>
<li>所谓匿名插槽，就是这个插槽<code>&lt;slot&gt;&lt;/slot&gt;</code>没有<code>name</code>属性，使用者放进来的东西，都扔进这个插槽中。</li>
<li>匿名插槽是一种特殊的具名插槽，也就是没有命名的插槽</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 在子组件中，使用特殊的元素&lt;slot&gt;就可以为子组件开启一个插槽。</span><br><span class="line">Vue.component(<span class="string">&#x27;err-message&#x27;</span>,&#123;</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;span style = &quot;fontWeight: 800&quot;&gt;错误信息为:&lt;/span&gt;</span></span><br><span class="line"><span class="string">        &lt;slot&gt;默认错误&lt;/slot&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">      `</span></span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line"># 该插槽插入什么内容取决于父组件如何使用。</span><br><span class="line">&lt;err-message&gt;&lt;/err-message&gt;</span><br><span class="line">&lt;err-message&gt;<span class="number">404</span>&lt;/err-message&gt;</span><br><span class="line">&lt;err-message&gt;<span class="xml"><span class="tag">&lt;<span class="name">h3</span>&gt;</span>500<span class="tag">&lt;/<span class="name">h3</span>&gt;</span></span>&lt;/err-message&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>例子:</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">  &lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;err-message&gt;&lt;/err-message&gt;</span><br><span class="line">    &lt;err-message&gt;<span class="number">404</span>&lt;/err-message&gt;</span><br><span class="line">    &lt;err-message&gt;<span class="xml"><span class="tag">&lt;<span class="name">h3</span>&gt;</span>500<span class="tag">&lt;/<span class="name">h3</span>&gt;</span></span>&lt;/err-message&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">  Vue.component(<span class="string">&#x27;err-message&#x27;</span>,&#123;</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;span style = &quot;fontWeight: 800&quot;&gt;错误信息为:&lt;/span&gt;</span></span><br><span class="line"><span class="string">        &lt;slot&gt;默认错误&lt;/slot&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">      `</span></span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="keyword">let</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">&#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>效果:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200824/^KwmeoaGSqSI.png" alt="效果图"></p>
</li>
</ul>
</li>
</ul>
<hr>
</li>
</ul>
<ul>
<li><p><strong>具名插槽:</strong></p>
<ol>
<li>当有多个插槽时，我们只想替换其中一个，就需要用到具名插槽了</li>
<li>所谓具名插槽，就是这个插槽里，这个插槽被命了名(<code>name</code>属性有值了)，想要向这个具名插槽中插入东西时，声明插槽的名称就行了</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 用name属性给&lt;slot&gt;&lt;/slot&gt;标签命名</span><br><span class="line">Vue.component(<span class="string">&#x27;text-message&#x27;</span>,&#123;</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;header&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;header&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/header&gt;</span></span><br><span class="line"><span class="string">        &lt;main&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;main&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/main&gt;</span></span><br><span class="line"><span class="string">        &lt;footer&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;footer&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/footer&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">      `</span></span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line"># 使用template标签声明具名插槽名称&lt;template v-slot:插槽名&gt;&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;text-message&gt;</span><br><span class="line">      &lt;template v-slot:header&gt;</span><br><span class="line">        &lt;h3&gt;这是标题内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template v-slot:main&gt;</span><br><span class="line">        &lt;h3&gt;这是主要内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template v-slot:footer&gt;</span><br><span class="line">        &lt;h3&gt;这是结尾内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">    &lt;/text-message&gt;</span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>例子:</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=<span class="string">&quot;en&quot;</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">  &lt;div id=<span class="string">&quot;app&quot;</span>&gt;</span><br><span class="line">    &lt;text-message&gt;</span><br><span class="line">      &lt;template v-slot:header&gt;</span><br><span class="line">        &lt;h3&gt;这是标题内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template v-slot:main&gt;</span><br><span class="line">        &lt;h3&gt;这是主要内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template v-slot:footer&gt;</span><br><span class="line">        &lt;h3&gt;这是结尾内容&lt;/h3&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">    &lt;/text-message&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;https://cdn.jsdelivr.net/npm/vue/dist/vue.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">  Vue.component(<span class="string">&#x27;text-message&#x27;</span>,&#123;</span><br><span class="line">    template:<span class="string">`</span></span><br><span class="line"><span class="string">      &lt;div&gt;</span></span><br><span class="line"><span class="string">        &lt;header&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;header&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/header&gt;</span></span><br><span class="line"><span class="string">        &lt;main&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;main&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/main&gt;</span></span><br><span class="line"><span class="string">        &lt;footer&gt;</span></span><br><span class="line"><span class="string">          &lt;slot name = &quot;footer&quot;&gt;&lt;/slot&gt;</span></span><br><span class="line"><span class="string">        &lt;/footer&gt;</span></span><br><span class="line"><span class="string">      &lt;/div&gt;</span></span><br><span class="line"><span class="string">      `</span></span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="keyword">let</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">&#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>效果:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200824/3ZclMn69iTx6.png" alt="效果图"></p>
</li>
</ul>
</li>
</ul>
<hr>
<ul>
<li><h4 id="作用域插槽"><a href="#作用域插槽" class="headerlink" title="作用域插槽:"></a>作用域插槽:</h4><ul>
<li><p><strong>概念:</strong></p>
<p>​    可以绑定数据的插槽，显示内容完全由子组件决定，数据来自子组件。作用域插槽的样式由父组件决定</p>
</li>
<li><p><strong>使用:</strong></p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"># 在子组件的&lt;template&gt;模板中动态绑定要暴露给父组件的属性</span><br><span class="line">&lt;template id=<span class="string">&quot;list-message&quot;</span>&gt;</span><br><span class="line">      &lt;div&gt;</span><br><span class="line">        &lt;slot :list = <span class="string">&#x27;list&#x27;</span>&gt;&lt;/slot&gt;</span><br><span class="line">      &lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line"># 父组件: 我们先来看2.6版本之前的写法</span><br><span class="line">&lt;list-message&gt;</span><br><span class="line">      &lt;template slot-scope = <span class="string">&quot;slotProps&quot;</span>&gt;</span><br><span class="line">        &lt;ul&gt;</span><br><span class="line">          &lt;li v-<span class="keyword">for</span> = <span class="string">&quot;(item,index) in slotProps.list&quot;</span> :key = <span class="string">&quot;index&quot;</span>&gt;&#123;&#123;item&#125;&#125;&lt;/li&gt;</span><br><span class="line">        &lt;/ul&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">&lt;/list-message&gt;</span><br><span class="line"></span><br><span class="line"># 父组件: 我们先来看2.6版本之后的写法</span><br><span class="line">&lt;list-message&gt;</span><br><span class="line">      &lt;template v-slot = <span class="string">&quot;slotProps&quot;</span>&gt;</span><br><span class="line">        &lt;ul&gt;</span><br><span class="line">          &lt;li v-<span class="keyword">for</span> = <span class="string">&quot;(item,index) in slotProps.list&quot;</span> :key = <span class="string">&quot;index&quot;</span>&gt;&#123;&#123;item&#125;&#125;&lt;/li&gt;</span><br><span class="line">        &lt;/ul&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">&lt;/list-message&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>例子:</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200824/j*lNO5iD3DDg.png" alt="效果图"></p>
</li>
</ul>
</li>
</ul>
<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">六根清静</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liugenqingjing2.coding.me/2020/08/20/Vue%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%BA%8C-%E7%BB%84%E4%BB%B6%E5%8C%96%E5%BC%80%E5%8F%91/">https://liugenqingjing2.coding.me/2020/08/20/Vue知识点总结-二-组件化开发/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liugenqingjing2.coding.me" target="_blank">小何blog (记录美好)</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%B3%BB%E5%88%97%F0%9F%8F%AC/">系列🏬</a><a class="post-meta__tags" href="/tags/Vue/">Vue</a><a class="post-meta__tags" href="/tags/%E7%BB%84%E4%BB%B6%E5%8C%96/">组件化</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200820/3IlRh8gQ9aXk.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" target="_blank"><img class="post-qr-code-img" data-lazy-src="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/08/26/Vue%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%89-Vue%E5%AE%9E%E4%BE%8B%E7%9A%84%E5%B1%9E%E6%80%A7%E5%92%8C%E6%96%B9%E6%B3%95/"><img class="prev-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-7e36bbf302377459208d84f15c14562d_r.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Vue知识点总结(三.Vue实例的属性和方法)</div></div></a></div><div class="next-post pull-right"><a href="/2020/08/17/Vue%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%80/"><img class="next-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200817/Jcw3rhoMSX6V.jpeg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Vue知识点总结(一)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/08/17/Vue知识点总结-一/" title="Vue知识点总结(一)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200817/Jcw3rhoMSX6V.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-17</div><div class="title">Vue知识点总结(一)</div></div></a></div><div><a href="/2020/08/26/Vue知识点总结-三-Vue实例的属性和方法/" title="Vue知识点总结(三.Vue实例的属性和方法)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-7e36bbf302377459208d84f15c14562d_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-26</div><div class="title">Vue知识点总结(三.Vue实例的属性和方法)</div></div></a></div><div><a href="/2020/09/02/Vue知识点总结-五-Vue路由-vue-router-下/" title="Vue知识点总结(五.Vue路由(vue-router)下)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-bc9025226078d28671970bfabf6bf9c3_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-02</div><div class="title">Vue知识点总结(五.Vue路由(vue-router)下)</div></div></a></div><div><a href="/2020/08/27/Vue知识点总结-四-生命周期/" title="Vue知识点总结(四.生命周期简介与钩子函数)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-47003f6638666652d3f0cf9cae7d81f8_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-27</div><div class="title">Vue知识点总结(四.生命周期简介与钩子函数)</div></div></a></div><div><a href="/2020/08/30/Vue知识点总结-五-Vue路由-vue-router上/" title="Vue知识点总结(五.Vue路由(vue-router)上)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-57b6e9af0b62b0c8e5856f1eb58bb8cd_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-30</div><div class="title">Vue知识点总结(五.Vue路由(vue-router)上)</div></div></a></div><div><a href="/2020/08/14/HTML5新特性-一-语义化标签/" title="HTML5新特性(一.语义化标签)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/1597229144765.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-14</div><div class="title">HTML5新特性(一.语义化标签)</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">六根清静</div><div class="author-info__description">记录美好，记录生活，记录学习</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/he_chaoming/dashboard/projects?scope=public&amp;&amp;sort="><i class="fab fa-gofore"></i><span>My Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/he1213114428" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:484695754@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="tencent://message/?uin=484695754" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div></div><div class="card-widget card-recent-post"><div id="gamenews"><div class="card-content"><div class="item-headline"><i class="fas fa-cube"></i><span>ROLL资讯</span><i class="fas fa-retweet" @click="changetype(current)" style="float:right;margin-top:8px"></i></div><div class="newsbar"><span v-for="(type, index) in listtype" v-on:click="addClass(index)" v-bind:class="{ listtypeon:index==current}">{{type}}</span></div><div class="aside-list"><div class="aside-list-item" v-for="(news,index) in newsvue"><a class="thumbnail" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title"><img class="loaded" onerror="this.onerror=null;this.src='/img/404.jpg'" data-ll-status="loaded" :src="news.imgList[0]"/></a><div class="content"><a class="title" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title">{{news.title}}</a><time>{{news.postTime}}</time></div></div></div></div><div id="newsmodal"><button class="modalclose" @click="hidemodle()">关闭</button><h2>{{newpostvue.title}} </h2><h4>{{newpostvue.ptime}} &nbsp;&nbsp; {{newpostvue.source}}</h4><div v-html="newpostvue.content"></div></div></div></div><div class="card-widget card-shuo"><div class="card-content" style="height:auto;min-height:280px;"><div class="item-headline"><i class="fas fa-comments"></i><span>&#x8BF4;&#x8BF4</span><a id="shuovisualchange" style="cursor:pointer;float:right" onclick="shuovisualchange()">编辑</a></div><div id="artitalk_main" style="width:100%;height:100%;padding:10px"></div></div></div><div class="sticky_layout"></div><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-paw fa-spin"></i><span>那年今日</span></div><div id="history-news" style="height: 100px;overflow: hidden;"><div id="history-card"></div></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">大学生一枚，软件工程，想做全栈攻城狮，哈哈，有兴趣可以加 QQ:484695754 (也可以点上面的logo)，一起交流学习</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue%E7%BB%84%E4%BB%B6%E5%8C%96"><span class="toc-number">1.</span> <span class="toc-text">Vue组件化</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%BB%84%E4%BB%B6%E5%8C%96%E7%9A%84%E6%A6%82%E5%BF%B5"><span class="toc-number">1.1.</span> <span class="toc-text">1.组件化的概念:</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E7%BB%84%E4%BB%B6%E5%8C%96%E5%BC%80%E5%8F%91%E7%9A%84%E4%BC%98%E7%82%B9"><span class="toc-number">1.2.</span> <span class="toc-text">2.组件化开发的优点:</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E7%BB%84%E4%BB%B6%E6%B3%A8%E5%86%8C%E6%96%B9%E5%BC%8F"><span class="toc-number">1.3.</span> <span class="toc-text">3.组件注册方式:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Vue%E5%8F%88%E5%88%86%E4%B8%BA%E5%85%A8%E5%B1%80%E6%B3%A8%E5%86%8C%E5%92%8C%E5%B1%80%E9%83%A8%E6%B3%A8%E5%86%8C%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%9D%A5%E6%B3%A8%E5%86%8C%E7%BB%84%E4%BB%B6%E3%80%82%E5%85%A8%E5%B1%80%E7%BB%84%E4%BB%B6%E5%AE%83%E5%8F%AF%E4%BB%A5%E5%9C%A8%E4%BB%BB%E4%BD%95-%E6%A0%B9-%E5%AE%9E%E5%88%97%E4%B8%AD%E4%BD%BF%E7%94%A8%E7%9A%84%E7%BB%84%E4%BB%B6%EF%BC%8C%E5%B1%80%E9%83%A8%E7%BB%84%E4%BB%B6%E5%8F%AA%E8%83%BD%E5%9C%A8%E6%9F%90%E4%B8%80%E5%AE%9E%E5%88%97%E4%B8%AD%E4%BD%BF%E7%94%A8%E7%9A%84%E7%BB%84%E4%BB%B6%E3%80%82"><span class="toc-number">1.3.0.1.</span> <span class="toc-text">Vue又分为全局注册和局部注册两种方式来注册组件。全局组件它可以在任何(根)实列中使用的组件，局部组件只能在某一实列中使用的组件。</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%A8%E5%B1%80%E6%B3%A8%E5%86%8C%E7%BB%84%E4%BB%B6"><span class="toc-number">1.3.1.</span> <span class="toc-text">全局注册组件:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8"><span class="toc-number">1.3.1.1.</span> <span class="toc-text">注:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%80%E9%83%A8%E7%BB%84%E4%BB%B6%E6%B3%A8%E5%86%8C"><span class="toc-number">1.3.2.</span> <span class="toc-text">局部组件注册:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B3%A8-1"><span class="toc-number">1.3.3.</span> <span class="toc-text">注:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E5%91%BD%E5%90%8D%E6%96%B9%E5%BC%8F"><span class="toc-number">1.3.4.</span> <span class="toc-text">组件命名方式:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E9%97%B4%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BA%A4%E4%BA%92"><span class="toc-number">1.3.5.</span> <span class="toc-text">组件间的数据交互:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%88%B6%E7%BB%84%E4%BB%B6%E5%90%91%E5%AD%90%E7%BB%84%E4%BB%B6%E4%BC%A0%E5%80%BC"><span class="toc-number">1.3.5.1.</span> <span class="toc-text">父组件向子组件传值:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-2"><span class="toc-number">1.3.5.2.</span> <span class="toc-text">注:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%90%E7%BB%84%E4%BB%B6%E5%90%91%E7%88%B6%E7%BB%84%E4%BB%B6%E4%BC%A0%E5%80%BC"><span class="toc-number">1.3.5.3.</span> <span class="toc-text">子组件向父组件传值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-3"><span class="toc-number">1.3.5.4.</span> <span class="toc-text">注:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%9D%9E%E7%88%B6%E7%BB%84%E4%BB%B6%E8%B7%9F%E5%AD%90%E7%BB%84%E4%BB%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BC%A0%E5%80%BC%EF%BC%88%E4%BA%8B%E4%BB%B6%E6%80%BB%E7%BA%BF%EF%BC%89%EF%BC%9A"><span class="toc-number">1.3.5.5.</span> <span class="toc-text">非父组件跟子组件之间的传值（事件总线）：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8-4"><span class="toc-number">1.3.5.6.</span> <span class="toc-text">注:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E7%BB%84%E4%BB%B6%E6%8F%92%E6%A7%BD"><span class="toc-number">1.4.</span> <span class="toc-text">4.组件插槽:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E6%8F%92%E6%A7%BD%E7%9A%84%E6%A6%82%E5%BF%B5"><span class="toc-number">1.4.0.1.</span> <span class="toc-text">组件插槽的概念</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8"><span class="toc-number">1.4.0.2.</span> <span class="toc-text">作用:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8F%92%E6%A7%BD%E7%9A%84%E5%88%86%E7%B1%BB"><span class="toc-number">1.4.0.3.</span> <span class="toc-text">插槽的分类:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F%E6%8F%92%E6%A7%BD"><span class="toc-number">1.4.0.4.</span> <span class="toc-text">作用域插槽:</span></a></li></ol></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210321/qWPEashJOuNK.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十三.跨域介绍和JSONP介绍)"/></a><div class="content"><a class="title" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)">Node.js学习(二十三.跨域介绍和JSONP介绍)</a><time datetime="2021-03-21T13:40:58.000Z" title="发表于 2021-03-21 21:40:58">2021-03-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/CvAoe6kC5*f2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十二.Node.js项目流程(下))"/></a><div class="content"><a class="title" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))">Node.js学习(二十二.Node.js项目流程(下))</a><time datetime="2021-03-20T14:33:29.000Z" title="发表于 2021-03-20 22:33:29">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/gSrAfCznw@^F.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十一.Node.js项目流程(中))"/></a><div class="content"><a class="title" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))">Node.js学习(二十一.Node.js项目流程(中))</a><time datetime="2021-03-15T04:35:12.000Z" title="发表于 2021-03-15 12:35:12">2021-03-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/UMp@B^akHmf8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十.Node.js项目流程(上))"/></a><div class="content"><a class="title" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))">Node.js学习(二十.Node.js项目流程(上))</a><time datetime="2021-03-14T14:36:58.000Z" title="发表于 2021-03-14 22:36:58">2021-03-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210227/EcgLTE4WPOp^.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(十九.封装操作数据库和CSRF)"/></a><div class="content"><a class="title" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)">Node.js学习(十九.封装操作数据库和CSRF)</a><time datetime="2021-02-27T13:20:18.000Z" title="发表于 2021-02-27 21:20:18">2021-02-27</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 六根清静</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi,  welcome  to  my  <a  href="">blog</a>!</div><div class="icp"><a><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>豫ICP备2020025430号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module" defer></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 50000);</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'kW2ft895T235y7DxmyJmXX5X-MdYXbMMI',
      appKey: 'v0zBPCAdwiJ0xg4s4eSfusLD',
      placeholder: '建议使用QQ邮箱，评论头像采用QQ头像',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: 'https://???????.api.lncldglobal.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      master: '1f76478c4ec918ffc6d50de6b68db531'.split(','),
      friends: '5c?????bfe6rfc72a????e268ad3819c,7c?????bfe65fc02a????e2????3919c'.split(','),
      tagMeta: '博主,小伙伴,访客'.split(',')
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src='https://cdn.jsdelivr.net/npm/artitalk'></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script src="/js/list.js"></script><script src="/js/gitcalendar.js"></script><script src="/js/calendar.js"></script><script src="/js/xkTool.js"></script><script src="/js/pjax.js"></script><script src="/magnet/js/vue.min.js"></script><script src="/magnet/js/catalogMagnet.js"></script><script src="/js/airvisualapi.js"></script><script src="/js/history.js"></script><script src="/js/historyroll.js"></script><script src="/js/change.js"></script><script type="text/javascript" src="https://www.airvisual.com/scripts/widget_v2.0.js"></script><script> setTimeout(function(){$('.monoline').eq(0).html($(".monoline strong").eq(0).text().replace('°','℃'));},5000);</script><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="/js/myBg.js"></script><script src="/js/shuo.js"></script><script src="/js/artitalkkey.js"></script><script src="/news/js/keys.js"></script><script src="/news/js/news.js"></script><script src="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/js/pool.min.js"><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/stars/stars.js"></script><script src="https://cdn1.lncld.net/static/js/3.5.0/av-min.js"></script><script src="/zan/zan.js"></script><div class="aplayer no-destroy" data-id="2916766519" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" muted></div><script src="/swiper/swiper.min.js"></script><script src="/swiper/swiperindex.js"></script><script async src="//at.alicdn.com/t/font_2264842_3izu8i5eoc2.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="/js/third-party/fireworks.js"></script><script src="/js/third-party/activate-power-mode.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6fdec148.js","daovoice")
</script><script>var isChatBtn = true
daovoice('init', {
  app_id: '6fdec148',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (true) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/unitychan.model.json"},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":true,"scale":0.6},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body></html>